package com.healthcare.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.healthcare.admin.pojo.Transferttype;
import com.healthcare.admin.pojo.User;
import com.healthcare.admin.query.UserQuery;
import com.healthcare.admin.service.TransferttypeService;
import com.healthcare.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 转诊类型表 前端控制器
 * </p>
 *
 * @author 新华医院转诊联盟
 * @since 2020-04-12
 */
@Api(tags = "后台转诊管理")
@RestController
@RequestMapping("/admin/transferttype")
public class TransferttypeController {
    @Autowired
    private TransferttypeService transferttypeService;

    @ApiOperation(value = "转诊门诊新增")
    @PostMapping("/save")
    public Result save(
            @ApiParam(name = "transferttype", value = "门诊新增对象", required = true)
            @RequestBody Transferttype transferttype){
        transferttype.setDeleted(false);
        transferttypeService.save(transferttype);
        return Result.ok();
    }

    @ApiOperation(value = "根据转诊ID删除信息")
    @DeleteMapping("{id}")
    public Result removeById(
            @ApiParam(name = "id", value = "转诊ID", required = true)
            @PathVariable Integer id){
        transferttypeService.deleteUserInfoById(id);
        return Result.ok();
    }

    @ApiOperation(value = "分页后台科室字典列表")
    @GetMapping("{page}/{limit}")
    public Result pageQuery(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit
    ){
        Page<Transferttype> pageParam = new Page<>(page, limit);

        transferttypeService.pageQuery(pageParam);

        List<Transferttype> records = pageParam.getRecords();

        long total = pageParam.getTotal();

        return  Result.ok().data("total", total).data("rows", records);
    }

    @ApiOperation(value = "根据ID查询科室信息")
    @GetMapping("{id}")
    public Result getById(
            @ApiParam(name = "id", value = "科室ID", required = true)
            @PathVariable Integer id){

        Transferttype transferttype = transferttypeService.getById(id);
        return Result.ok().data("item", transferttype);
    }

    @ApiOperation(value = "根据ID修改科室信息")
    @PutMapping("update/{id}")
    public Result updateById(
            @ApiParam(name = "id", value = "科室ID", required = true)
            @PathVariable Integer id,

            @ApiParam(name = "adminofficeService", value = "科室对象", required = true)
            @RequestBody Transferttype transferttype){
        transferttype.setId(id);
        transferttypeService.updateById(transferttype);
        return Result.ok();
    }

}

